#
# @lc app=leetcode.cn id=496 lang=python3
#
# [496] 下一个更大元素 I
#

# @lc code=start
class Solution:
    def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
        right = [-1]*len(nums2)
        s = []
        for i in range(len(nums2)-1, -1, -1):
            v = nums2[i]
            while s and s[-1]<v:
                s.pop()
            if s:
                right[i] = s[-1]
            s.append(v)
        tmpMap = {}
        for i, v in enumerate(nums2):
            tmpMap[v] = i
        return [right[tmpMap[j]] for j in nums1]
        

# @lc code=end

